<template>
  <Dialogdrawerdefect :ddtvisible="dialogVisible" size="505px" @close="handleClose" direction="rtl" :has-modal="true" :modal="true" :close-on-click-modal="true">
    <div class="cont_box" v-loading="loading">
      <AppInfoTitle>
        <b class="fs-16">{{`日志详情【${ruleForm.ftime}】`}}</b>
      </AppInfoTitle>
      <el-form inline class="rule-form" ref="form" :model="ruleForm">
        <el-form-item label="医院名称:" prop="hospitalName" class="short-input">
          <el-input v-model="ruleForm.hospitalName" readonly></el-input>
        </el-form-item>
        <el-form-item label="操作人员:" prop="foperatorno" class="short-input">
          <el-input v-model="ruleForm.foperatorno" readonly></el-input>
        </el-form-item>
        <el-form-item label="操作时间:" prop="ftime" class="short-input">
          <el-input v-model="ruleForm.ftime" readonly></el-input>
        </el-form-item>
        <el-form-item label="操作类别:" prop="fthings" class="short-input">
          <el-input v-model="ruleForm.fthings" readonly></el-input>
        </el-form-item>
        <!-- <el-form-item label="患者姓名:" prop="patientName" class="short-input">
          <el-input v-model="ruleForm.patientName" readonly></el-input>
        </el-form-item>
        <el-form-item label="影像号:" prop="patientXno" class="short-input">
          <el-input v-model="ruleForm.patientXno" readonly></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="检查部门:" prop="dep" class="short-input">
          <el-input v-model="ruleForm.dep" readonly></el-input>
        </el-form-item> -->
        <el-form-item label="报告描述:" prop="describle" class="short-input">
          <el-input v-model="ruleForm.describle" readonly></el-input>
        </el-form-item>
        <el-form-item label="报告诊断:" prop="conclusion" class="short-input">
          <el-input v-model="ruleForm.conclusion" readonly></el-input>
        </el-form-item>
        <!-- <el-form-item label="检查项目:" prop="checkpos" class="short-input">
          <el-input v-model="ruleForm.checkpos" readonly></el-input>
        </el-form-item> -->
        <el-form-item label="IP地址:" prop="mac" class="short-input">
          <el-input v-model="ruleForm.mac" readonly></el-input>
        </el-form-item>
        <el-form-item label="模块:" prop="moduleName" class="short-input">
          <el-input v-model="ruleForm.moduleName" readonly></el-input>
        </el-form-item>
        <el-form-item label="软件版本:" prop="operatorSoft	" class="short-input">
          <el-input v-model="ruleForm.operatorSoft	" readonly></el-input>
        </el-form-item>
        <el-form-item label="相关Id:" prop="flogId" class="short-input">
          <el-input v-model="ruleForm.flogId" readonly></el-input>
        </el-form-item>
        <el-form-item v-if="showTextarea" label="日志信息:" prop="allcontent" class="describe-input">
          <el-input type="textarea" :rows="10" v-model="ruleForm.allcontent" readonly></el-input>
        </el-form-item>
        <div v-else>
          <div class="text-block" v-for="(value,key) in allContentArr" :key="key">
            <el-form-item :label="key+':'" prop="allcontent" class="short-input large-width">
              <div class="content-block">
                <el-form-item :label="k+':'" class="mini-input" v-for="(v,k) in value" :key="k">
                  <el-input :value="v" readonly></el-input>
                </el-form-item>
              </div>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div class="buttons">
        <div class="left-buttons">
          <el-button size="small" @click="handleClose">关 闭</el-button>
        </div>
      </div>
    </div>
  </Dialogdrawerdefect>
</template>
<script>
import Dialogdrawerdefect from '@/components/dialogbox/dialogDrawer'
import AppInfoTitle from '@/components/appInfoTitle/index'
import { getFlogModel } from '@/api/api.js'
export default {
  name: 'EditDialog',
  components: {
    Dialogdrawerdefect, AppInfoTitle
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    id: {
      String,
      default: ''
    },
    hospitalCode: {
      String,
      default: ''
    }

  },
  data() {
    return {
      ruleForm: {},
      allContentArr: {},
      loading: false,
      showTextarea: false
    }
  },
  watch: {
    id(val) {
      if (val) {
        this.getDetail(val)
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('myClose')
    //   this.ruleForm = {}
    },
    async getDetail(id) {
      await this.$getHospitalList()
      this.loading = true
      getFlogModel({ id: id, hospitalCode: this.hospitalCode }).then(res => {
        this.loading = false
        if (res && res.code === 10000) {
          this.ruleForm = res.content
          let obj = this.mx_hospitalList.find(v => {
            return v.code === this.ruleForm.hospitalCode
          })
          if (obj) {
            this.ruleForm.hospitalName = obj.name
          }
          this.showTextarea = false
          if (this.ruleForm.checkId) {
            this.dealAllContent()
          } else if (this.ruleForm.allcontent) {
            this.showTextarea = true
          }
        }
      }).catch(() => {
        this.loading = false
      })
    },
    dealAllContent() {
      this.allContentArr = {}
      let ac = this.ruleForm.allcontent
      if (ac) {
        // console.log('ac', ac)
        ac = ac.replaceAll('。', '')
        let index1 = 0// 病人基本信息
        let index2 = ac.indexOf('病人检查信息')
        let index3 = ac.indexOf('病人预约信息')
        let str1 = ac.substring(index1 + 6, index2)// 病人基本信息
        let str2 = ac.substring(index2 + 6, index3)// 病人检查信息
        let str3 = ac.substring(index3 + 6)// 病人预约信息
        let allStr = {
          '病人基本信息': str1,
          '病人检查信息': str2,
          '病人预约信息': str3
        }
        for (let key in allStr) {
          let strArr = allStr[key].split('；')
          let obj = {}
          for (let i = 0; i < strArr.length; i++) {
            let arr = strArr[i].split('：')
            if (arr[0] !== '操作人员') {
              obj[arr[0]] = arr[1]
            }
          }
          this.allContentArr[key] = obj
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.cont_box{
  /* height: calc(100vh - 98px); */
  height: calc(100vh - 60px) !important;
  /* padding: 16px 24px; */
  padding: 19px 19px;
  overflow-y: auto;
  .short-input{
      width: 200px;
      margin-right: 23px!important;
      margin-bottom: 5px;
      .el-input{
          width: 200px;
      }
  }
  .mini-input{
      width: 185px;
      margin-right: 15px !important;
      margin-bottom: 5px;
      .el-input{
          width: 185px;
      }
  }
  .large-width{
      width: 424px;
      /deep/ .el-textarea__inner{
          width: 424px;
      }
  }
  .describe-input{
      /deep/ .el-form-item__content{
          width: 430px;
      }
  }
  .name{
      font-weight: bold;
  }
  .el-form--inline .el-form-item{
      margin-right:0px
  }
  .text-block{
      background: #f5f5f5;
      padding: 0 10px;
      margin-top: 10px;
  }
  .content-block{
     padding: 0 10px;
  }
}
</style>
